package news.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import news.entity.Author;
import news.service.AuthorService;
import news.service.impl.AuthorServiceImpl;

public class AuthorServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		AuthorService as = new AuthorServiceImpl();
		
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		HttpSession session = request.getSession();
//		PrintWriter out = response.getWriter();
		String opr = request.getParameter("opr");
		if("findAllAuthor".equals(opr)){
			List<Author> auList = as.findAllAuthor();
			session.setAttribute("auList", auList);
			response.sendRedirect("jsp/showAuthor.jsp");
			
		}
		
		
	}

}
